using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.IO;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_ProductRecycleManage : Member, IRequiresSessionState
{
	private string linkHead = "";
	protected Literal ltrTitle;
	protected DropDownList ddlProdcutType;
	protected TextBox txtProductName;
	protected Button SeachBut;
	protected GridView gvManage;
	protected Literal ltrPagePanel;
	protected Button btnMoreDelete;
	protected Button btnMoreBack;
	protected PlaceHolder phManage;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.BindProductByIsDeleted();
		}
	}
	protected void BindProductByIsDeleted()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		string query = this.GetQuery();
		string queryByOrder = this.GetQueryByOrder();
		int num = this.gvManage.PageIndex;
		if (Fetch.Get("pageindex") != null)
		{
			num = Convert.ToInt32(Fetch.GetID("pageindex").ToString());
			if (num == 0)
			{
				num = 1;
			}
		}
		string text = " from HLShop_Product where EnableSingleSell=1 and IsDeleted=1 and SalerID=" + base.user.UserID + " ";
		int pageSize = this.gvManage.PageSize;
		ClientByPage clientByPage = new ClientByPage();
		int listCount = clientByPage.GetListCount("select count(*)" + text + query);
		string url = "ProductRecycleManage.aspx?1=1" + this.linkHead + "&pageindex";
		int startIndex = (num - 1) * pageSize + 1;
		int endIndex = num * pageSize;
		string str = "ROW_NUMBER() OVER (" + queryByOrder + ") as row,ProductID,ProductType,ProductSmallImageUrl,ProductName,PUnit,StandPrice,Hits,IsDeleted ";
		string strSQL = "select " + str + text + query;
		DataTable listPage = clientByPage.GetListPage(strSQL, "row", startIndex, endIndex);
		this.gvManage.DataSource = listPage;
		this.gvManage.DataBind();
		if (listPage.Rows.Count > 0)
		{
			this.ltrPagePanel.Text = currPageLinks.CurrPageLink(num, pageSize, listCount, "条记录", url);
		}
	}
	protected string GetQuery()
	{
		string text = "";
		string text2 = Fetch.Get("ProductType");
		if (!string.IsNullOrEmpty(text2))
		{
			for (int i = 0; i < this.ddlProdcutType.Items.Count; i++)
			{
				this.ddlProdcutType.Items[i].Selected = false;
				if (this.ddlProdcutType.Items[i].Value == text2)
				{
					this.ddlProdcutType.Items[i].Selected = true;
					break;
				}
			}
		}
		else
		{
			text2 = this.ddlProdcutType.SelectedValue.Trim();
		}
		if (!string.IsNullOrEmpty(text2) && text2 != "0")
		{
			text = text + " and ProductType=" + text2;
		}
		this.linkHead = this.linkHead + "&ProductType=" + text2;
		string text3 = Fetch.Get("ProductName");
		if (!string.IsNullOrEmpty(text3))
		{
			if (text3 != this.txtProductName.Text.Trim())
			{
				text3 = this.txtProductName.Text.Trim();
			}
			this.txtProductName.Text = text3;
		}
		else
		{
			text3 = this.txtProductName.Text;
		}
		if (!string.IsNullOrEmpty(text3))
		{
			text = text + " and ProductName like '%" + text3 + "%'";
			this.linkHead = this.linkHead + "&ProductName=" + text3;
		}
		return text;
	}
	private string GetQueryByOrder()
	{
		return "order by ProductID desc";
	}
	protected void gvManage_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void gvManage_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.gvManage.PageIndex = e.NewPageIndex;
		this.BindProductByIsDeleted();
	}
	protected void Button_Command(object sender, CommandEventArgs e)
	{
		string comeUrl = "ProductRecycleManage.aspx?1=1" + this.linkHead + "&pageindex";
		string commandName = e.CommandName;
		if (commandName == "MoreDelete")
		{
			string text = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
			if (!string.IsNullOrEmpty(text))
			{
				int num = 0;
				string[] array = text.Split(new char[]
				{
					','
				});
				for (int i = 0; i < array.Length; i++)
				{
					int productidDel = int.Parse(array[i]);
					num = this.DelProduct(productidDel);
				}
				if (num > 0)
				{
					this.WriteErrMsg("", "批量信息删除成功！", comeUrl);
				}
			}
			else
			{
				this.WriteErrMsg("", "请选择您要删除的信息", "");
			}
		}
		else
		{
			if (commandName == "DelInfo")
			{
				string text2 = e.CommandArgument.ToString();
				int num = this.DelProduct(Convert.ToInt32(text2));
				if (num > 0)
				{
					this.WriteErrMsg("", "批量信息删除成功！", comeUrl);
				}
			}
			else
			{
				if (commandName == "EditBack")
				{
					string text2 = e.CommandArgument.ToString();
					string sql = "update HLShop_Product set IsDeleted=0 where ProductID=" + text2;
					int num = this.conn.Execute(sql);
					if (num > 0)
					{
						this.WriteErrMsg("", "还原成功！", comeUrl);
					}
				}
				else
				{
					if (commandName == "MoreBakc")
					{
						string text3 = Text.CheckNumList(Fetch.GetOrPost("SelectId"));
						if (text3 != "")
						{
							int num2 = 0;
							string text4 = text3;
							string[] array2 = text4.Split(new char[]
							{
								','
							});
							for (int j = 0; j < array2.Length; j++)
							{
								string sql = "update HLShop_Product set IsDeleted=0 where ProductID=" + array2[j];
								num2 = this.conn.Execute(sql);
							}
							if (num2 > 0)
							{
								this.WriteErrMsg("", "批量信息还原成功！", comeUrl);
							}
						}
						else
						{
							this.WriteErrMsg("", "请选择您要还原的信息", "");
						}
					}
				}
			}
		}
		this.BindProductByIsDeleted();
	}
	private int DelProduct(int productidDel)
	{
		string sql = "select ProductSmallImageUrl from HLShop_Product where ProductID=" + productidDel;
		DataTable dataTable = this.conn.GetDataTable(sql);
		if (dataTable.Rows.Count > 0)
		{
			string text = dataTable.Rows[0]["ProductSmallImageUrl"].ToString();
			if (text != null && text != "")
			{
				string path = base.Server.MapPath("../" + text);
				if (File.Exists(path))
				{
					File.Delete(path);
				}
			}
		}
		int num = this.conn.Execute("delete HL_GroupShopProduct where MainProductID=" + productidDel);
		int num2 = this.conn.Execute("delete HLShop_ProductImg where ProductID=" + productidDel);
		return this.conn.Execute("delete HLShop_Product where ProductID=" + productidDel);
	}
	protected void SeachBut_Click(object sender, EventArgs e)
	{
		this.BindProductByIsDeleted();
	}
	protected string GetStatus(object value)
	{
		string result = value.ToString();
		if (value.ToString().ToLower().Trim() == "1")
		{
			result = "<span style='color:Green; font-size:12px;'>回收站中</span>";
		}
		else
		{
			if (value.ToString().ToLower().Trim() == "0")
			{
				result = "<span style='color:Red; font-size:12px;'>仓库中</span>";
			}
		}
		return result;
	}
}
